<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>03_1.BufferGeometry</title>
    <style>
        body {
            margin: 0;
        }
    </style>
</head>

<body>
    <script src="build/three.js"></script>
    <script>
        //生成场景
        const scene = new THREE.Scene();
        //设置相机
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.z = 5;
        //设置渲染器
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
        //生成模型
        const geometry = new THREE.BufferGeometry();
        //构成模型的点
        const vertices = new Float32Array([
            -1.0, -1.0, 1.0,
            1.0, -1.0, 1.0,
            1.0, 1.0, 1.0,
        ]);
        geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
        const greenMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
        const object = new THREE.Mesh(geometry, greenMaterial);

        //设置场景
        scene.add(object);
      
        //渲染场景
        renderer.render(scene, camera);
    </script>
</body>

</html>